var page = require('webpage').create(),
    system = require('system'),
    address, output, height;

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: screenshot.js <URL> <filename>');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    height = system.args[3];
    page.paperSize = {
        width: '450px',
        height: height/2 + 'px',
        margin: '0px'
    };
    page.zoomFactor = 0.5;
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 400);
        }
    });
}